package com.xzx;

import jakarta.jms.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.ActiveMQConnectionFactory;

/**
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/9/5 22:32
 */
@Slf4j
public class ConsumerFromTopic {
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("admin", "admin", "tcp://localhost:61616");
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession();

        Topic topic = session.createTopic("xzx_topic");
        MessageConsumer consumer = session.createConsumer(topic);
        Message message = consumer.receive();
        log.info("message: {}", message);
        consumer.close();
        session.close();
        connection.close();
    }
}
